﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Easyui扩展库 Datagrid - 落阳 整理</title>
    <link href="http://www.easyui-extlib.com/Content/Site.css" rel="stylesheet" />
    <script src="http://www.easyui-extlib.com/Scripts/jquery/jquery-1.11.0.min.js"></script>
    <script src="http://www.easyui-extlib.com/Scripts/jquery-extensions/jquery.jdirk.js"></script>
    <link href="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/themes/default/easyui.css" rel="stylesheet" />
    <link href="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/themes/icon.css" rel="stylesheet" />
    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>

    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.findRow.js"></script>
    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.deleteRow.js"></script>
    <script>
        $(function () {
            var getFrozenColumns = function () {
                var result = [];

                var c1 = [];
                c1.push({ field: 'ID', title: '主键', width: 100 });
                c1.push({ field: 'AreaName', title: '地区', width: 150 });
                c1.push({ field: 'Sex1', title: '男', width: 90 });
                c1.push({ field: 'Sex2', title: '女', width: 90 });

                result.push(c1);

                return result;
            };

            var getColumns = function () {
                var result = [];

                var normal00000 = [
                    { field: 'TS1', title: '测试1', width: 60 },
                    { field: 'TS2', title: '测试2', width: 60 }
                ];
                result.push(normal00000);

                return result;
            };
            var options = {
                title: "列表",
                idField: "ID",
                rownumbers: true,
                fit: true,
                border: false,
                singleSelect: true,
                toolbar: [
                    {
                        iconCls: 'icon-remove',
                        text: "删除 索引 为 0 的数据行",
                        handler: function () {
                            $("#dg1").datagrid("deleteRow", 0); $(this).linkbutton("disable");
                        }
                    },
                    "-",
                    {
                        iconCls: 'icon-remove',
                        text: "删除 id 为 3 的数据行",
                        handler: function () {
                            $("#dg1").datagrid("deleteRow", "3");
                            $(this).linkbutton("disable");
                        }
                    },
                    "-",
                    {
                        iconCls: 'icon-remove',
                        text: "先获取 id 为 5 的数据行，然后当做参数去删除",
                        handler: function () {
                            var row = $("#dg1").datagrid("findRow", "5");
                            $("#dg1").datagrid("deleteRow", row); $(this).linkbutton("disable");
                        }
                    },
                    "-",
                    {
                        iconCls: 'icon-remove',
                        text: "删除 id 为 6、7 的数据行集合",
                        handler: function () {
                            $("#dg1").datagrid("deleteRows", ["6", "7"]); $(this).linkbutton("disable");
                        }
                    },
                    "-",
                    {
                        iconCls: 'icon-remove',
                        text: "删除 索引大于11 的数据行集合",
                        handler: function () {
                            $("#dg1").datagrid("deleteRows", function (itemRow, index, allRows) { return index > 11; }); $(this).linkbutton("disable");
                        }
                    }
                ],
                frozenColumns: getFrozenColumns(),
                columns: getColumns(),
                method: "get",
                url: "datagrid-common-data.json",
                onBeforeDeleteRow: function (index, row) { if (String(row["ID"]).toInteger() <= 15) { return true; } else { alert("数据[id = " + row.ID + "]不可删除。"); return false; } },
                onDeleteRow: function (index, row) { alert("删除数据[id = " + row.ID + "]成功。"); }
            };

            $("#dg1").datagrid(options);
        });
    </script>
</head>
<body>
    <div class="easyui-panel" data-options="fit:true,border:false,title:'注意：ID超过15的数据是无法被删除的！'">
        <table id="dg1"></table>
    </div>
</body>
</html>
